package core;

import static core.SeleneseTestCaseEx.*;

public class Check {
	private static HandlingError err = HandlingError.getInstance();

	public void verifyTitle(String expectedTitle) {
		repEng.newCheck("Title should contains '" + expectedTitle + "' text.");
		try {
			String title = browser.getTitle();
			if (!title.contains(expectedTitle)) {
				err.setFailDesc("Real title is '" + title + "'");
			}
			
		} catch (Exception e) {
			err.setErrDesc(e);
		} finally {
			err.checkResult();
		}	
	}
	
	public void checkWarningUserCreation(String mainText) {
		repEng.newCheck("There should be displayed  '" + mainText + "' warning.");
		try {
			if (!browser.isTextPresent(mainText)) {
				err.setFailDesc("The warning is not presented'");
			}
			
		} catch (Exception e) {
			err.setErrDesc(e);
		} finally {
			err.checkResult();
		}	
	}
	
	public void checkTextEmail(String text) {
		repEng.newCheck("Mail should contained '" + text + "' text.");
		try {
			err.setWarnDesc("Very dificult for implementation!");
			//browser.click("locator");//TODO needs for change
			//browser.waitForPageToLoad(tc.getEnv("waitpageload"));

			//if (!browser.isTextPresent(text)) {
			//	err.setFailDesc("Mail doesnot contain the text'");
			//}
			
		} catch (Exception e) {
			err.setErrDesc(e);
		} finally {
			err.checkResult();
		}
	}
	
	public void checkTextOnPage(String warnText) {
		repEng.newCheck("There should be displayed '" + warnText + "' text on page.");
		try {
			if (!browser.isTextPresent(warnText)) {
				err.setFailDesc("The text was not found on page");
			}
			
		} catch (Exception e) {
			err.setErrDesc(e);
		} finally {
			err.checkResult();
		}
	}	
	
	public void checkNoTextOnPage(String warnText) {
		repEng.newCheck("There should not be displayed '" + warnText + "' text on page.");
		try {
			if (browser.isTextPresent(warnText)) {
				err.setFailDesc("The text was found on page");
			}
			
		} catch (Exception e) {
			err.setErrDesc(e);
		} finally {
			err.checkResult();
		}
	}
	
	public void difficultToImplement(String text) {
		repEng.newCheck(text);
		
		try {
		err.setWarnDesc("This check is difficult for implementation!");
		err.checkResult();
		} catch (Exception e) {
		}
	}
	
	public void checkTextInElement(String locator, String text) {
		repEng.newCheck("There is displayed '" + text + "' text in '" + locator + "' element");
		try {
			if (!browser.getText(locator).toLowerCase().contentEquals(text)) {
				err.setFailDesc("The '" + text + "' was not found in '" + locator + "' element");
			}			
		} catch (Exception e) {
			err.setErrDesc(e);
		} finally {
			err.checkResult();
		}
	}

}

